package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.VoteItem;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VoteItemDAO{
	
	@SQL("SELECT * FROM voteItem WHERE deleteFlag=1 AND subjectId=:t.subjectId ORDER BY orderNum LIMIT :t.start,:t.length ")
    List<Map> query(@SQLParam("t") VoteItem voteItem);
	
	@SQL("SELECT count(*) FROM voteItem WHERE deleteFlag=1 AND subjectId=:t.subjectId ")
    int querysize(@SQLParam("t") VoteItem voteItem);
    
    @SQL("select * from voteItem where id=:1")
    VoteItem queryById(int id);
    
    @SQL("INSERT INTO voteItem (voteId,subjectId,item,count,deleteFlag,createUser,createAt,updateUser,updateAt,orderNum) VALUES (:1,:2,:3,0,1,:4,now(),:4,now(),:5)")
    void create(int voteId, int subjectId, String item, String user, int orderNum);
	
	@SQL("UPDATE voteItem SET voteId=:2,subjectId=:3,item=:4,updateUser=:5,updateAt=now(),orderNum=:6 WHERE id=:1")
	void update(int itemId, int voteId, int subjectId, String item,
			String user, int i);
	
	@SQL("UPDATE voteItem SET count=count+1 WHERE id=:1")
    void updateCount(int id);
	
	@SQL("UPDATE voteItem SET count=:2 WHERE id=:1")
    void updateCount(int id,int count);
    
    @SQL("UPDATE voteItem SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE voteItem SET stickAt=now(),updateAt=now() WHERE id=:1")
	void updateByStickTime(int id);

    @SQL("UPDATE voteItem SET stickAt=null,updateAt=now() WHERE id=:1")
	void updateByStickTimeIsNull(int id);

    @SQL("SELECT * FROM voteItem WHERE deleteFlag=1 AND subjectId=:1 order by orderNum")
	List<Map> queryBySubjectId(int subjectId);

}